<template>
  <!-- 主布局容器 -->
  <el-container v-if="showMainLayout" class="app-container">
    <!-- 侧边栏 -->
    <el-aside width="200px" class="app-aside">
      <sidebar />
    </el-aside>

    <!-- 主内容区 -->
    <el-container>
      <!-- 顶部导航 -->
      <el-header height="60px" class="app-header">
        <header-bar />
      </el-header>

      <!-- 页面内容 -->
      <el-main>
        <router-view v-slot="{ Component }">
          <transition name="fade-transform" mode="out-in">
            <component :is="Component" />
          </transition>
        </router-view>
      </el-main>
    </el-container>
  </el-container>

  <!-- 独立页面容器 -->
  <router-view v-else v-slot="{ Component }">
    <transition name="fade" mode="out-in">
      <component :is="Component" />
    </transition>
  </router-view>
</template>

<script setup>
import { computed } from 'vue'
import { useRoute } from 'vue-router'
import Sidebar from '@/components/Sidebar.vue'
import HeaderBar from '@/components/Header.vue'

const route = useRoute()

// 布局显示判断逻辑
const showMainLayout = computed(() => {
  // 通过路由meta控制显示
  if (typeof route.meta.showLayout !== 'undefined') {
    return route.meta.showLayout
  }
  
  // 默认逻辑：需要认证的页面显示布局
  return route.meta.requiresAuth
})
</script>

<style lang="scss" scoped>
.app-container {
  height: 100vh;
  
  .app-aside {
    background-color: #001529;
    transition: width 0.28s;
  }

  .app-header {
    display: flex;
    align-items: center;
    background: #fff;
    box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
  }
}

// 过渡动画
.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.3s;
}

.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}

.fade-transform-enter-active,
.fade-transform-leave-active {
  transition: all 0.3s;
}

.fade-transform-enter-from {
  opacity: 0;
  transform: translateX(-30px);
}

.fade-transform-leave-to {
  opacity: 0;
  transform: translateX(30px);
}
</style>